require('../../assets/css/index.less');
require('../../assets/fonts/iconfont.css');

require("../../lib/weui/weui.css")
let weui = require("../../lib/weui/weui.js")

require('./courseList.less')

const dom = require('../../utils/dom');
const https = require('../../utils/https');
const local = require('../../utils/local');

import Swiper, { Pagination, Autoplay } from 'swiper';
import 'swiper/swiper-bundle.min.css';
Swiper.use([Pagination, Autoplay])


dom.ready(function () {

    dom.tMenu('courseList');

    dom.bMenu('courseRun');


    function getCourseList() {
        https.get('/api/train/courseList', function (res) {

            let { errno, data } = res;

            if (errno == 0) {
                console.log(data);

                let newCourse = data.filter(v => v.courseId == 1);
                rander('#newsBox', newCourse)


                let courseList = data.filter(v => v.courseId > 1);
                rander('#tmsBox', courseList)
            }
        })
    }
    getCourseList()


    function rander(obj, data) {

        let htmlStr = '';

        data.map(v => {
            htmlStr += `<li class="mt20">
            <img data-id="${v.courseId}" src="http://fitness.h5.itsource.cn:3701${v.imgurl}" alt="">
            <div class="title">
                <h4>${v.name}</h4>
                <p class="c9a">${v.desc}</p>
            </div>
           </li>`
        })
        dom.getEle(obj).innerHTML = htmlStr;
    }


//方式二: 使用本地存储---2.实现点击事件
    dom.addEvent('#newsBox',function(event){

        if(event.target.nodeName=='IMG'){

            let val=event.target.getAttribute('data-id');
            location.href='courseDetails.html?id='+val

            console.log(val);
        }
    })




})



